<template>
  <div class="container">
    <div class="login-wrapper">
      <div class="header">注册</div>
      <div class="form-wrapper">
        <el-form
          :model="form"
          status-icon
          :rules="rules"
          ref="form"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item class="input-item" prop="name">
            <el-input
              type="text"
              name="username"
              placeholder="请输入用户名"
              v-model="form.name"
            ></el-input>
          </el-form-item>
          <el-form-item class="input-item" prop="phone">
            <el-input
              type="text"
              name="username"
              placeholder="请输入手机号码"
              v-model="form.phone"
            ></el-input>
          </el-form-item>
          <el-form-item class="input-item" prop="pwd">
            <el-input
              type="password"
              name="password"
              placeholder="请输入密码"
              v-model="form.pwd"
              prop="pwd"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item class="input-item" prop="pwd1">
            <el-input
              v-model="form.pwd1"
              type="password"
              name="password"
              placeholder="请确认密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="btn" @click="register">立即注册</el-button>
            <div class="msg">
              已有账号
              <router-link to="/mylogin"> 立即登录</router-link>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        pwd: "",
        name: "",
        phone: "",
        pwd1: "",
      },
      rules: {
        name: { required: true, message: "账户名不能为空", trigger: "blur" },
        phone: { required: true, message: "手机号不能为空", trigger: "blur" },
        pwd: { required: true, message: "密码不能为空", trigger: "blur" },
        pwd1: { required: true, message: "密码不能为空", trigger: "blur" },
      },
    };
  },
  methods: {
    register(form) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log("55555");
          let params = {
            pwd: this.form.pwd,
            name: this.form.name,
            phone: this.form.phone,
          };
          this.$http.userApi.add(params).then((res) => {
            // console.log(res);
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "注册成功，去登录",
              });
              this.$router.push("/mylogin");
            }
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.container {
  width: 100%;
  height: 100vh;
  border: none;
  background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
  // position: relative;
  // display: flex;
}
.login-wrapper {
  background-color: #fff;
  width: 358px;
  height: 588px;
  // margin: 0 auto;
  padding: 0 60px 0 0;
  border-radius: 15px;
  // align-items: center;
  // justify-content: center;
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.header {
  font-size: 38px;
  font-weight: bold;
  // text-align: center;
  margin-left: 150px;
  line-height: 100px;
}
.input-item {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  // border: 0;
  // padding: 10px;
  // border-bottom: 1px solid rgb(128, 125, 125);
  font-size: 15px;
  outline: none;
}
// 以大写印刷
// .input-item:placeholder {
//   text-transform: uppercase;
// }
.btn {
  text-align: center;
  border: none;
  padding: 10px;
  width: 80%;
  margin-top: 20px;
  background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
  color: #fff;
  margin-left: 20px;
}
.msg {
  text-align: center;
  line-height: 66px;
  margin-left: -10px;
}
a {
  text-decoration-line: none;
  color: #abc1ee;
}
.demo-ruleForm {
  margin-left: -20px;
}
</style>